<!-- 登录 -->
<template>
	<view>
		<!-- #ifndef MP-WEIXIN -->
		<view class="wrap u-flex u-flex-col u-row-between">
			<view class="content">
				<view class="title">欢迎登录</view>
				<input class="u-border-bottom" type="number" maxlength="11" v-model="tel" placeholder="请输入手机号" />
				<view class="tips">未注册的手机号验证后自动创建账号</view>
				<button @tap="submit" :style="[inputStyle]" class="getCaptcha">获取短信验证码</button>
				<view class="alternative">
					<view class="password">
						<!-- 密码登录 -->
					</view>
					<view class="issue">遇到问题</view>
				</view>
			</view>
			<view class="buttom" v-if="platform!='ios'">
				<view class="loginType">
					<view class="wechat item" @click="getuserinfo">
						<view class="icon">
							<u-icon size="70" name="weixin-fill" color="rgb(83,194,64)"></u-icon>
						</view>
						微信
					</view>
					<!-- 苹果登录 -->
					<view class="sign-in-with-apple" v-if="system >= 13 && platform=='ios'" @click="appleLogin">sign in
						with apple</view>
					<!-- <view class="QQ item">
						<view class="icon">
							<u-icon size="70" name="qq-fill" color="rgb(17,183,233)"></u-icon>
						</view>
						QQ
					</view> -->
				</view>
				<view class="hint">
					登录代表同意
					<text class="link">问题终结者用户协议、隐私政策，</text>
					并授权使用您的问题终结者账号信息（如昵称、头像、收获地址）以便您统一管理
				</view>
			</view>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tel: '',
				agentid: '',
				system: '', // 系统版本
				platform: '', // 平台
			}
		},
		async onLoad(e) {
			if (e.share) {
				this.agentid = e.agentid;
			}
			// #ifdef APP-PLUS

			// 先判断 系统版本
			uni.getSystemInfo({
				success: (res) => {
					this.system = res.system
					this.platform = res.platform
				},
				fail: (err) => {},
				complete: () => {}
			})
			// #endif
		},
		computed: {
			inputStyle() {
				let style = {};
				if (this.$u.test.mobile(this.tel)) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		methods: {
			// 苹果登录
			appleLogin() {
				// 判断是 iOS13版本
				uni.login({
					provider: 'apple',
					success: (loginRes) => {
						uni.getUserInfo({
							provider: 'apple',
							success: (userInfoRes) => {},
							fail: (err) => {}
						})
					},
					fail: (err) => {}
				})
			},
			async getuserinfo() {
				// #ifdef H5
				if (this.isWxBrowser()) {
					let res5 = await this.$u.api.wxlogin_p();
					if (res5) {
						location.href = res5.data.url;
					}
				}
				// #endif
				// #ifdef APP-PLUS
				// 唤起微信授权
				this.handleThirdLoginApp();
				// #endif
			},
			handleThirdLoginApp() {
				var that = this
				uni.getProvider({
					service: 'oauth',
					success: function(res) {
						//支持微信
						if (res.provider.indexOf('weixin')) {
							uni.login({
								provider: 'weixin',
								success: function(loginRes) {
									//请求登录接口方法
								},
								fail: function(err) {}
							})
						}
					}
				});
			},
			async submit() {
				if (this.$u.test.mobile(this.tel)) {
					let res = await this.$u.api.MobileCode_p({
						mobile: this.tel,
						scene: 1,
						is_login: 1
					})
					if (res) {
						let url = '/pages/login/code?tel=' + this.tel;
						if (res.is_show == 1) {
							url += '&agentid=' + res.agentid
						}
						this.$u.route({
							url: url
						})
					}
				}
			}
		}
	};
</script>

<style lang="scss" scoped>

</style>
